#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define MAX_N 20006

int n,root,tree_cnt;
struct lnode{
    int val;
    int cnt,sum;
    int lcnt,lsum;
    int lch,rch;
    int self;

    char * toString(){
        char *buff = (char *) malloc(1000* sizeof(char));
        sprintf(buff,"val=%d , cnt=%d, sum=%d, lcnt=%d, lsum=%d, lch=%d, rch=%d",val,cnt,sum,lcnt,lsum,lch,rch);
        return buff;
    }
}tree[MAX_N];

struct cnode{
    int v;
    int p;
}cow[MAX_N];

struct cmp{
    bool operator()(const cnode &a ,const cnode &b){
        return a.v < b.v;
    }
};

struct cmp_p{
    bool operator()(const cnode &a ,const cnode &b){
        return a.p < b.p;
    }
};

int mk_tree(int l,int r){
    if (r<l) return -1;
    int m = (l+r)/2;

    int lch = mk_tree(l,m-1);
    int rch = mk_tree(m+1,r);
    tree_cnt++;
    //cout << m<<" "<<tree_cnt<<" "<<lch<<" "<< rch << endl;
    tree[tree_cnt].lch = lch;
    tree[tree_cnt].rch = rch;
    tree[tree_cnt].val = cow[m].p;
    return tree_cnt;
}

void print_tree(){
    for (int i = 1 ; i <= tree_cnt ; i++){
        printf("#%d: %s\n",i,tree[i].toString());
    }
}

void Insert(int p,int root){
    tree[root].cnt ++;
    tree[root].sum +=p;
    if (p>tree[root].val){
        Insert(p,tree[root].rch);
    }
    if (p<tree[root].val){
        tree[root].lcnt++;
        tree[root].lsum+=p;
        Insert(p,tree[root].lch);
    }
    if (p==tree[root].val) tree[root].self++;
}

void get_less(int p , int root,  int &lcnt, int &lsum){
    if (p == tree[root].val) {
        lcnt += tree[root].lcnt;
        lsum += tree[root].lsum;
        return ;
    }
    if (p > tree[root].val){
        lcnt += tree[root].self + tree[root].lcnt;
        lsum += tree[root].self*tree[root].val + tree[root].lsum;
        get_less(p,tree[root].rch,lcnt,lsum);
    }
    if (p<tree[root].val)
        get_less(p,tree[root].lch,lcnt,lsum);
}



int main(){
   // freopen("1990.txt","r",stdin);
    scanf("%d",&n);
    for (int i =  0; i < n ;i++){
        scanf("%d%d",&cow[i].v,&cow[i].p);
    }

    sort(cow,cow+n,cmp_p());

    tree_cnt = 0;
    memset(tree,0,sizeof(tree));

    root = mk_tree(0,n-1);

    sort(cow,cow+n,cmp());
    int lcnt,lsum,rcnt,rsum;
    long long ans = 0,lt,rt;

    for (int i = 0 ; i < n ; i++){
        lcnt = lsum = 0;

        get_less(cow[i].p,root,lcnt,lsum);
        rcnt = tree[root].cnt - lcnt;
        rsum = tree[root].sum - lsum;
        lt =   cow[i].p * lcnt - lsum;
        rt =   rsum - cow[i].p * rcnt;
        ans += cow[i].v*(lt + rt);

        Insert(cow[i].p,root);
    }
    cout << ans <<endl;
    return 0;
}
